




**** MAPS AVERAGE YEAR ****


	
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
		

		
		xi: xtivreg2 cuminst roofrelativeIV  i.quarter  [aweight =NCust	], fe cluster(postcode) 
		
		predict ehat , e
		
		
		
		gen cumhat = cum - ehat
		
		
collapse (sum) NCustomer, by(postcode)

gen sample=1

*merge with map data
merge m:1 postcode using Data/PostcodeArea.dta
	drop if _merge ==2 
	drop _merge
	
	
merge m:1 postcode using Data/SA3postcode.dta
drop if _merge ==2 
drop _merge

merge m:1 SA3_CODE16 using "data/maps/sa3" 
drop if _merge ==2 
drop _merge

** missing SA3 codes are not Melbourne

*  melbourne

gen Melbourne = 1 if SA4_CODE=="213" | SA4_CODE =="210" | SA4_CODE=="209" | SA4_CODE =="207" | SA4_CODE=="211"  | SA4_CODE=="208" | SA4_CODE=="206" | SA4_CODE=="212"
replace Melbourne =0 if Melbourne ==.

gen Mornington = 1 if SA4_CODE =="214"
replace Mornington = 0 if Mornington ==.

gen Geelong = 1 if SA4_CODE=="203"
replace Geelong = 0 if Geelong ==.


gen Country = 1 if Melbourne ==0 & Mornington == 0 & Geelong==0
replace Country =0 if Country==.


merge m:1 postcode using Data/Postcode_matching.dta
drop if _merge ==2 
drop _merge


** for calculation of scale see Getmapscale.do

spmap NCustomer using Data/poa_coord , id(id) fcolor(Blues2) ndfcolor(white) ///
ndocolor(white)  clmethod(custom) clbreaks(2 6 14 24 50 113 235 609 934 1359 5792) ///
 osize(0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt) ocolor(white white white white white white white white white white ) scalebar(units(100) scale(89.5)  label(Kilometers) xpos(100))  mosize(none) mocolor(gs8) ///
legend(size(9pt) pos(2)) point(data("Data/GPO.dta") xcoord(x) ycoord(y) size(medlarge) fcolor(gs0) ocolor(white) osize(1.5pt))

graph export Analysis/NCustomer_pcode.png, replace




spmap NCustomer using Data/poa_coord if Melbourne ==1, id(id) fcolor(Blues2) ndfcolor(white) ///
ndocolor(white)   clmethod(custom) clbreaks(2 6 14 24 50 113 235 609 934 1359 5792) osize(0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt) ocolor(white 			white white white white white white white white white )  scalebar(units(10) scale(89.5)  label(Kilometers) xpos(100)) mosize(none) mocolor(gs8)   ///
legend(off) point(data("Data/GPO.dta") xcoord(x) ycoord(y) size(medlarge) fcolor(gs0) ocolor(white) osize(1.5pt))

graph export Analysis/NCustomerMelb_pcode.png, replace






